package cn.edu.zjut.mina.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	/**
	 * 两个日期相减获取相差的秒数
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int getSeconds(Date date1, Date date2) {
		int seconds = (int) (date1.getTime() > date2.getTime() ? date1.getTime() - date2.getTime() : date2.getTime() - date1.getTime())/1000;
		return seconds;
	}
	
	/**
	 * 两个日期相减获取相差的天数
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int getDays(Date date1, Date date2) {
		int day = getSeconds(date1, date2) / (60 * 60 * 24);
		return day;
	}
	
	/**
	 * 返回当前系统时间
	 * */
	public static String getTime() {
		  Date nowTime = new Date(System.currentTimeMillis());
		  SimpleDateFormat sdFormatter = new SimpleDateFormat("MM-dd HH:mm:ss");
		  String retStrFormatNowDate = sdFormatter.format(nowTime);
		  return retStrFormatNowDate;
	}
}
